Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
How to alert user before leaving webpage and run ajax function if user presses "ok"?

I have this function that is supposed to ask the user if they are sure that they want to leave or refresh the website and if they say yes and leave the ajax function is executed. My problem is if the ajax function is alone the user is given no warning but if anything else is in the code the ajax function doesn't work.

<script type="text/javascript">
            window.onbeforeunload = function () {
                return "";
                $.ajax({url: "checkout.php", type : 'post', data : { page_left: 1}});
            }
       </script>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

    <script type="text/javascript">
            window.onbeforeunload = function () {
 if (window.confirm("Do you really want to leave?")) {
  $.ajax({url: "checkout.php", type : 'post', data : { page_left: 1}});
} } </script>

Check this will help

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!